package main

import (
	"fmt"
)

func main() {
	root, err := BuildLaneTree()
	if err != nil {
		panic(err)
	}

	heroBuilder, err := NewHeroBuilder()
	if err != nil {
		panic(err)
	}

	playerNames := make([]string, 5)
	for i := 0; i < len(playerNames); i++ {
		fmt.Printf("请输入参赛玩家%d: ", i+1)
		if _, err := fmt.Scanf("%s", &playerNames[i]); err != nil {
			panic(err)
		}
	}

	var heroesIndex, nodeIndex int
	count := 0
	for count < 5 {
		fmt.Printf("------ Round %d ------\n", count+1)
		fmt.Println("---------------------")
		fmt.Println("可选位置组")
		nodes := root.RandomNodes(6)
		for i, node := range nodes {
			fmt.Printf("编号%d: %s\n", i+1, node.Beatify(playerNames))
		}

		fmt.Println("---------------------")
		fmt.Println("可选英雄组")
		heroes := heroBuilder.RandomHeroes(6)
		for i, hero := range heroes {
			fmt.Printf("编号%d: \n%s\n", i+1, heroBuilder.Beatify(hero))
		}
		fmt.Println("---------------------")

		for {
			fmt.Println("英雄组编号: ")
			n, err := fmt.Scanf("%d", &heroesIndex)
			if err != nil {
				fmt.Println(err)
				continue
			}

			if n != 1 {
				fmt.Println("invalid input")
				continue
			}

			break
		}

		for {
			fmt.Println("位置组编号: ")
			n, err := fmt.Scanf("%d", &nodeIndex)
			if err != nil {
				fmt.Println(err)
				continue
			}

			if n != 1 {
				fmt.Println("invalid input")
				continue
			}

			break
		}

		root = nodes[nodeIndex-1]
		heroBuilder.Remove(heroes[heroesIndex-1])

		count++
	}
}
